/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-10-22
 * Time: 20:56
 */
import java.util.*;

public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String b = sc.next();
        RomanNumeral ra = new RomanNumeral(a);
        RomanNumeral rb = new RomanNumeral(b);
        System.out.println(ra);
        System.out.println(rb.toInt());
        System.out.println(ra.add(rb));
        System.out.println(ra.minus(rb));
        System.out.println(ra.mul(rb));
    }
}
class RomanNumeral {
    private int number;
    private String romanNumber;
    private static final Map<Character, Integer> romanToIntMap = new HashMap<>();
    int[] array1={1000,900,500,400,100,90,50,40,10,9,5,4,1};
    String[] array2={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};

    static {
        // 初始化罗马数字到整数的映射
        romanToIntMap.put('I', 1);
        romanToIntMap.put('V', 5);
        romanToIntMap.put('X', 10);
        romanToIntMap.put('L', 50);
        romanToIntMap.put('C', 100);
        romanToIntMap.put('D', 500);
        romanToIntMap.put('M', 1000);
    }

    // 以一个整数为参数的构造器，指明罗马数字的实际值
    public RomanNumeral(int number) {
        this.number = number;
    }

    // 以一个字符串为参数的构造器，指明罗马数字的实际显示形式
    public RomanNumeral(String romanNumber) {
        this.romanNumber = romanNumber;
        this.number = fromRoman(romanNumber);
    }

    // 辅助方法：将罗马数字字符串转换为整数
    private int fromRoman(String roman) {
        int result = 0;
        int prevValue = 0;
        for (int i = roman.length() - 1; i >= 0; i--) {
            int currentValue = romanToIntMap.get(roman.charAt(i));
            if (currentValue < prevValue) {
                result -= currentValue;
            } else {
                result += currentValue;
            }
            prevValue = currentValue;
        }
        return result;
    }

    // 将罗马数字以基本符号的组合来表示
    @Override
    public String toString() {
        return toRoman(this.number);
    }

    // 辅助方法：将整数转换为罗马数字字符串
    private String toRoman(int num) {
        StringBuilder stringBuilder=new StringBuilder();
        int number1=number;
        while (number1>0){
            for (int i = 0; i < array1.length; i++) {
                if(number1>=array1[i]){
                    stringBuilder.append(array2[i]);
                    number1=number1-array1[i];
                    i=-1;
                }
            }
        }
        return stringBuilder.toString();
    }

    // 将罗马数字以整数方式表达
    public int toInt() {
        return this.number;
    }

    // 罗马数字的加法，返回两个本罗马数字与给定的罗马数字op的和
    public RomanNumeral add(RomanNumeral op) {
        return new RomanNumeral(this.number + op.number);
    }

    // 罗马数字的减法，返回两个本罗马数字与给定的罗马数字op的差
    public RomanNumeral minus(RomanNumeral op) {
        return new RomanNumeral(this.number - op.number);
    }

    // 罗马数字的乘法，返回两个本罗马数字与给定的罗马数字op的积
    public RomanNumeral mul(RomanNumeral op) {
        return new RomanNumeral(this.number * op.number);
    }
}
